home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 7967 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.7 KB  |  62 lines

  1. Path: news.informatik.uni-muenchen.de!usenet
  2. From: Kurt Watzka <watzka@stat.uni-muenchen.de>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: realloc(NULL,100)
  5. Date: Thu, 29 Feb 1996 13:47:48 +0100
  6. Organization: Institut fⁿr Statistik
  7. Message-ID: <3135A074.640C@stat.uni-muenchen.de>
  8. References: <31346CB0.41C67EA6@jupiter.di.uminho.pt>
  9. NNTP-Posting-Host: pc7.stat.uni-muenchen.de
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 2.0 (WinNT; I)
  14.  
  15. Rui Bastos wrote:
  16.  
  17.  
  18. >    Does anybody knows what's the expected behaviour of this program?
  19. > #include <stdio.h>
  20. > #include <malloc.h>
  21.  
  22. Who knows what your non-standard header <malloc.h> contains.
  23. Maybe it defines something like
  24.  
  25. #define realloc(x, y)    exit(*x - y)
  26.  
  27. Is there a specific reason _not_ to include <stdlib.h> if
  28. you want to use realloc()?
  29.  
  30. > main()
  31. > {
  32. >    void *x=NULL;
  33. >    x=realloc(NULL,100);
  34. >    printf("%p\n",x);
  35. > }
  36. >   I tested it under diferent compilers/operating systems
  37. > and  it returns null, others returns a valid address and other
  38. > crashes.
  39.  
  40. The expected behaviour with a _correct_ prototype for
  41. realloc() in scope is that "realloc() behaves like
  42. malloc() if the first parameter is NULL", so both 
  43. returning NULL and a valid address are within the realms
  44. of "expected behaviour".
  45.  
  46. > PS please and send me an email if you reply to this post.
  47.  
  48. If you want to reduce the noise level on this newsgroup,
  49. ask for email replies _and_ offer to post a summary of
  50. the answers you get.
  51.  
  52. There is a good reason _not_ to ask for private email replies.
  53. Sometimes the person that replies is _very_ wrong in his/her
  54. relpy. The collective wisdom of c.l.c will almost certainly
  55. spot inaccuracies in an answer and correct them.
  56.  
  57. Kurt
  58.